home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / c2man-2.0pl33.lha / c2man-2.0 / pc / updmake < prev   
Encoding:
Text File  |  1995-01-24  |  1.8 KB  |  100 lines

  1. #!/usr/local/bin/perl -w
  2. # This script updates the MSDOS & OS/2 Makefile.pc automatically from the Unix
  3. # one to minimise the possibility of me making a mistake.
  4. # It's a gross hack, but it works.
  5. open(MAKEFILE, "../Makefile") || die;
  6. rename("Makefile.pc", "Makefile.old") || die;
  7. open(PREVIOUS, "Makefile.old") || die;
  8. open(OUTPUT, ">Makefile.pc") || die;
  9.  
  10. # skip the header from the Unix Makefile.
  11. do { $_ = <MAKEFILE>; } until m/^SHELL=/o;
  12.  
  13. # retain the previous header from the PC Makefile.
  14. while (<PREVIOUS>)
  15. {
  16.     print OUTPUT;
  17.     last if /# DO NOT EDIT/;
  18. }
  19.  
  20. while (<MAKEFILE>)
  21. {
  22.     if ($_ eq "MAKE=make\n")
  23.     {
  24.         while (<MAKEFILE>)
  25.         {
  26.             last unless $_ eq "\n";
  27.         }
  28.     }
  29.  
  30.     next if /chmod/o;
  31.     s/\.o(\W)/\$O\1/go;
  32.     s/\.o$/\$O/o;
  33.     s/c2man([^.])/c2man.exe\1/ if (/:/ || /cp /);
  34.     s/^(install:) all$/\1/;
  35.     if (/\$\(LEX\) (.*)/)
  36.     {
  37.         print OUTPUT "\t\$(LEX) -t $1 > \$@";
  38.         print OUTPUT "\n";
  39.         $_ = "\tcp \$@ lex_yy.c\n";
  40.     }
  41.     print OUTPUT;
  42.     print OUTPUT "\t\$(BIND)\n" if (/\$\(LDFLAGS\) /);
  43.     last if m/^# y.tab.c dependancies/o;
  44. }
  45.  
  46. # output dependancies grouped into lines.
  47. sub output_depend
  48. {
  49.     return if $current eq "";
  50.  
  51.     $chars = length($current) + 1;
  52.     $current =~ s/\.o$/\$O/o;
  53.     print OUTPUT $current, ":";
  54.     foreach $file (@depends)
  55.     {
  56.         $chars += 1 + length($file);
  57.         if ($chars > 77)
  58.         {
  59.             print OUTPUT "\\\n\t";
  60.             $chars = 8 + length($file);
  61.         }
  62.         else
  63.         {
  64.             print OUTPUT " ";
  65.         }
  66.         print OUTPUT $file;
  67.     }
  68.     print OUTPUT "\n\n";
  69.     $current = "";
  70.     undef @depends;
  71. }
  72.  
  73. # process the dependancies a bit.
  74. $current = "";
  75. undef @depends;
  76. while (<MAKEFILE>)
  77. {
  78.     if (m/^#/ || $_ eq "\n")
  79.     {
  80.         &output_depend;
  81.         print OUTPUT;
  82.         next;
  83.     }
  84.  
  85.     # have we found a dependancy?
  86.     if (($obj,$dep) = m/^(.*):\s*(.*)/)
  87.     {
  88.         next if ($dep =~ m!^/!);    # ignore /usr/include
  89.         if ($obj ne $current)
  90.         {
  91.             &output_depend;
  92.             $current = $obj;
  93.         }
  94.         $dep =~ s!^\./!!;
  95.         push(@depends, $dep);
  96.     }
  97. }
  98.  
  99. close OUTPUT || die;
  100.